package com.tistory.iam1492.adapter;

import java.util.ArrayList;

import com.tistory.iam1492.activity.R;
import com.tistory.iam1492.beans.StarListBean;
import com.tistory.iam1492.util.ImageUtil;
import com.tistory.iam1492.util.SRUtil;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class RankListAdapter extends BaseAdapter {
	LayoutInflater mInflater;
	Context mContext;
	ArrayList<StarListBean> mArrList;
	
	public RankListAdapter(Context context, ArrayList<StarListBean> arrList) {
		mInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		this.mContext = context;
		this.mArrList = arrList;		
	}
	
	@Override
	public int getCount() {
		return mArrList.size();
	}

	@Override
	public Object getItem(int position) {
		return mArrList.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		if (convertView == null){
			convertView = mInflater.inflate(R.layout.sr_list_item, parent, false);
		}
		TextView tv_itemNum = (TextView)convertView.findViewById(R.id.tv_item_num);
		ImageView iv_itemPic = (ImageView)convertView.findViewById(R.id.iv_item_pic);
		TextView tv_itemName = (TextView)convertView.findViewById(R.id.tv_item_name);
		TextView tv_itemAge = (TextView)convertView.findViewById(R.id.tv_item_age);
		TextView tv_itemType = (TextView)convertView.findViewById(R.id.tv_item_type);
		TextView tv_itemVote = (TextView)convertView.findViewById(R.id.tv_item_vote);
		TextView tv_itemVoteDiff = (TextView)convertView.findViewById(R.id.tv_item_votediff);
		
		tv_itemNum.setText(String.valueOf(position + 1) + ".");
		tv_itemName.setText(mArrList.get(position).getName());
		tv_itemAge.setText("("+String.valueOf(mArrList.get(position).getAge())+")");
		tv_itemType.setText(" " + SRUtil.typeToString(mArrList.get(position).getType()));
		iv_itemPic.setImageBitmap(mArrList.get(position).getPic());
		tv_itemVote.setText(" "+mArrList.get(position).getVote());
		if (position != 0)
			tv_itemVoteDiff.setText(" (-" + (mArrList.get(position-1).getVote() - mArrList.get(position).getVote())+")");
		else
			tv_itemVoteDiff.setVisibility(View.GONE);
		return convertView;
	}
}
